<template>
  <div>
    <quill-editor
      ref="QuillEditor"
      v-model="content"
      :content="content"
      :options="editorOption"
      @change="onEditorBlur()"
    />
  </div>
</template>

<script>
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
import { addQuillTitle } from './quill-title'
import { quillEditor } from 'vue-quill-editor'
const toolbarOptions = [
  ['bold', 'italic', 'underline', 'strike'], // toggled buttons
  [{ list: 'ordered' }, { list: 'bullet' }],
  ['blockquote', 'code-block'],
  ['image']
]
export default {
  components: {
    quillEditor
  },
  props: {
    context: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      editorOption: {
        placeholder: '请输入编辑内容',
        theme: 'snow', // 主题风格
        modules: {
          toolbar: {
            container: toolbarOptions, // 工具栏
            handlers: {}
          }
        }
      }, // 富文本编辑器配置
      content: '' // 富文本内容
    }
  },
  watch: {
    context(val) {
      this.content = val
    }
  },
  mounted() {
    addQuillTitle()
  },
  methods: {
    onEditorBlur() {
      this.$emit('update', this.content)
    }
  }
}
</script>

<style scope>
.quill-editor {
  height: 200px;
  margin-bottom: 50px;
}
#quill-upload {
  opacity: 0;
}
</style>
